import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.http.StreamResponse;
import com.openai.models.chat.completions.ChatCompletionChunk;
import com.openai.models.chat.completions.ChatCompletionCreateParams;

import java.util.function.Consumer;

public class main {
    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.builder()
//                          bce-V3/ALTAK-al5a6CIT474ZPkr1bhoDD/b931077cd8f99138ca00717580beed95c41b4535
        //                  bce-V3/ALTAK-aI5a6CLT474ZPkr1bhoDD/b931077cd8f99138ca00717580beed95c41b4535
                //          bce-v3/ALTAK-fVhc9mL14zSp1ANizLsfO/b586427caa6a53be0da17fc039158244337b2f04
                .apiKey("bce-v3/ALTAK-fVhc9mL14zSp1ANizLsfO/b586427caa6a53be0da17fc039158244337b2f04") //将your_APIKey替换为真实值，如何获取API Key请查看：https://console.bce.baidu.com/iam/#/iam/apikey/list
                .baseUrl("https://qianfan.baidubce.com/v2/") //千帆ModelBuilder平台地址
                .build();

        ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
                .addUserMessage("你好") // 对话messages信息
                .model("ernie-4.5-turbo-128k") // 模型对应的model值，请查看支持的模型列表：https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43
                .build();

        StreamResponse<ChatCompletionChunk> chatCompletion = client.chat().completions().createStreaming(params);
        Consumer<ChatCompletionChunk> consumer = s -> System.out.println(s.choices().get(0).delta().content());
        chatCompletion.stream().forEach(consumer);
    }
}